import time
from selenium import webdriver
from selenium.webdriver import ActionChains
from yunma import YdmVerify

driver = webdriver.Chrome("D:/download_soft/chromedriver-win64/chromedriver-win64/chromedriver.exe")

# 需要打开的地址
url = "https://www.douban.com/"

driver.get(url)
driver.maximize_window()  # 窗口最大化

# 切换iframe
driver.switch_to.frame(0)  # 使用索引

# 获取密码登录节点
account = driver.find_element_by_css_selector("li.account-tab-account")
account.click()  # 点击密码登录节点

# 获取用户名输入框
username = driver.find_element_by_id("username")
username.send_keys("15973194541")

# 获取密码输入框
password = driver.find_element_by_id("password")
password.send_keys("asdfasd")

# 获取登录豆瓣节点
login = driver.find_element_by_css_selector("div.account-tabcon-start a.btn-account")
login.click()  # 点击登录豆瓣

time.sleep(2)
# 切换iframe
driver.switch_to.frame("tcaptcha_iframe_dy")

# 获取背景图片
slide_bg = driver.find_element_by_id("slideBg")
slide_bg.screenshot("douban.png")

# 创建云码验证实例
y = YdmVerify()

with open("douban.png", "rb") as fp:
    content = fp.read()
distance = y.sin_slide_verify(content)


# 移动滑块

chains = ActionChains(driver)  # 创建操作链
slider = driver.find_element_by_css_selector("#tcOperation div.tc-slider-normal")
# 点击并且按住
chains.click_and_hold(slider).move_by_offset(int(distance), 0).release().perform()  # 执行操作链






